﻿using System;
using System.IO;
using System.Net;
using AiFrame.Base.Core.Data.Access;
using AiFrame.Base.Core.Properties;
using AiFrame.InterfaceLib.Data.Access.NHibernateAccess;
using AiFrame.InterfaceLib.Licenses;

namespace AiFrame.Base.Core
{
    /// <summary>
    /// Speichert Einstellungen für die gesamten Applikationen oder
    /// ruft diese ab.
    /// </summary>
    public class ConfigurationProxy
    {
        public static string DatabaseName
        {
            get { return Settings.Default.DBName; }
            set{ Settings.Default.DBName = value;}
        }

        public static string DatabaseUsername
        {
            get { return Settings.Default.DBUsername; }
            set { Settings.Default.DBUsername = value;}
        }

        public static string DatabaseHostAddress
        {
            get { return Settings.Default.DBHostAddress; }
            set { Settings.Default.DBHostAddress = value;}
        }

        public static INHibernateSessionManager SessionManager
        {
            set{ DatabaseConnection.SessionManager = value;}
        }

        /// <summary>
        /// Legt den Application Name fest oder
        /// gibt ihn zurück.
        /// </summary>
        public static string ApplicationName
        {
            get; set;
        }

        /// <summary>
        /// Legt den Firmennamen fest oder gibt
        /// ihn zurück.
        /// </summary>
        public static string CompanyName
        {
            get; set;
        }
        
        /// <summary>
        /// Gets the application data directory.
        /// </summary>
        public static string AppDataDirectory
        {
            get
            {
                string curPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
                
                curPath = Path.Combine(curPath, CompanyName);
                curPath = Path.Combine(curPath, ApplicationName);

                if (!Directory.Exists(curPath))
                    Directory.CreateDirectory(curPath);

                return curPath;
            }
        }

        /// <summary>
        /// Sets or gets the network credentials for the 
        /// problem dialog.
        /// </summary>
        public static NetworkCredential NetworkCredential { get; set; }

        /// <summary>
        /// Gets or sets the smtp server address for the
        /// problem dialog.
        /// </summary>
        public static string ProblemDialogSmtpServer { get; set; }

        /// <summary>
        /// Gets or sets the mail address for the problem dialog.
        /// </summary>
        public static string ProblemDialogMailAddress { get; set; }

        /// <summary>
        /// Gets or sets the license manager.
        /// </summary>
        public static ILicenseManager LicenseManager { get; set; }
    }
}
